<template>
  <div style="position: relative;">
    <el-form :inline="true" size="mini" :model="formInline" label-position="right">
      <el-form-item label="知识类型名称">
        <el-input class="filter-item" v-model="formInline.businessName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="类型级别">
        <el-select v-model="formInline.businessLevel" placeholder="请选择">
          <el-option label="全部" value="0"></el-option>
          <el-option label="1级类型" value="1"></el-option>
          <el-option label="2级类型" value="2"></el-option>
          <el-option label="3级类型" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">搜索</el-button>
        <el-button type="warning" class="el-button--reset" icon="el-icon-refresh-right" @click="resetFromdata" size="mini"></el-button>
        <el-button type="primary" size="mini" @click="addFromdata">创建类型</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-table :data="tableData" size="mini" style="width: 100%;" header-cell-class-name="table-header-gray" v-loading="isShowloading">
          <el-table-column type="index" align="center" width="55" label="序号"></el-table-column>
          <el-table-column prop="typeName" align="center" label="知识类型" show-overflow-tooltip></el-table-column>
          <el-table-column prop="typeLevel" align="center" label="类型级别" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.typeLevel}}级
            </template>
          </el-table-column>
          <el-table-column prop="parentName" align="center" label="上级类别" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="creteUser" align="center" label="创建人" show-overflow-tooltip></el-table-column>
          <el-table-column prop="creteTime" align="center" label="创建时间" show-overflow-tooltip></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
              <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end" style="margin-top: 10px;">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNo"
            :page-size="page_size"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            :total="total"></el-pagination>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { Knowledgetype } from '@/api/business.js';
import Knowledgetypeadd from './Knowledgetypeadd.vue';
export default {
  name: 'Knowledgetype',
  data () {
    return {
      editDialogVisible: false,
      formInline: {
        businessName: null,
        businessLevel: null
      },
      tableData: [],
      total: 0,
      page_size: 10,
      pageNo: 1,
      isShowloading: false
    }
  },
  created () {
    this.loadKnowledgetypeWidgetData()
  },
  computed: {},
  methods: {
    /**
     * 知识类型
     */
    loadKnowledgetypeWidgetData () {
      let params = {
        ...this.formInline,
        size: this.page_size,
        current: this.pageNo
      }
      return new Promise((resolve, reject) => {
        Knowledgetype.list(this, params).then(res => {
          this.tableData = res.data.records
          this.total = res.data.total
        }).catch(e => {
          reject(e);
        });
      });
    },
    // 创建业务类型
    addFromdata () {
      let params = {};
      this.$dialog.show('新建', Knowledgetypeadd, {
        area: '800px'
      }, params).then(res => {
        this.loadKnowledgetypeWidgetData();
      }).catch(e => {});
    },
    // 搜索
    onSubmit () {
      this.pageNo = 1
      this.loadKnowledgetypeWidgetData()
    },
    // 重置
    resetFromdata () {
      this.formInline = {
        name: null,
        knowledgeType: null,
        catalogType: null,
        deptId: null
      }
      this.loadKnowledgetypeWidgetData()
    },
    // 分页导航
    handleCurrentChange (val) {
      this.pageNo = val
      this.loadKnowledgetypeWidgetData()
    },
    handleSizeChange (val) {
      this.page_size = val
      this.loadKnowledgetypeWidgetData()
    },
    currentChange (val) {
      this.pageNo = val
      this.loadKnowledgetypeWidgetData()
    },
    // 修改
    handleEdit (row) {
      this.$dialog.show(row ? '编辑业务类型' : '新建业务类型', Knowledgetypeadd, {
        area: '800px'
      }, {
        knowledgeId: row.id
      }).then(res => {
        this.loadKnowledgetypeWidgetData()
      }).catch(e => {
      });
    },
    // 删除
    handleDelete (row) {
      this.$confirm('确定要删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = row.id
        return new Promise((resolve, reject) => {
          Knowledgetype.delete(this, params).then(res => {
            this.loadKnowledgetypeWidgetData()
          }).catch(e => {
            reject(e);
          });
        });
      })
    }
  }
}
</script>
